<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ZHOUYANG
 * Date: 13-3-30
 * Time: 下午2:37
 */
 
Class Template{
    private $view = '';
    private $data = array();
    private $template = array();

    static public function show($template){
        global $_input,$_session,$site_configs;

        $view = isset($template['view']) ? $template['view'] : '';
        $data = isset($template['data']) ? $template['data'] : array();

        $controller = 'index';
        $action = 'index';
        if($view == ''){
            $dir_arr= explode('&',$_SERVER['QUERY_STRING']);

            foreach((array)$dir_arr as $k=>$v){
                $dir_name = explode('=',$v);

                if($dir_name[0] == 'm' && preg_match('/^[A-Za-z]+$/',$dir_name[1])){
                    $controller = $dir_name[1];
                }

                if($dir_name[0] == 'a' && preg_match('/^[A-Za-z]+$/',$dir_name[1])){
                    $action = $dir_name[1];
                }
            }

            $view = ucfirst(strtolower($controller)).'\\'.$action.'.php';
        }

        if (file_exists(VIEW_PATH . $view)){
            if($data){
                extract($data);
            }
            include VIEW_PATH . $view;
        }else{
            die('模板：'.VIEW_PATH.$view.'没有找到！');
        }
    }
}